import {
  LOGIN, ROUTES, 
  GETPHONECODE, UPDATEPWD, 
  REGISTER,GETUSERLIST,
  ROLEUPDATE, USERROLE, 
  USERMANAGE
} from '@/services/api'
import {request, METHOD, removeAuthorization} from '@/utils/request'

/**
 * 登录服务
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function login(params) {
  return request(LOGIN, METHOD.POST, params)
}

export async function getRoutesConfig() {
  return request(ROUTES, METHOD.GET)
}

export async function getPhoneCode(params) {
  return request(GETPHONECODE, METHOD.POST, params)
}

export async function updatePwd(params) {
  return request(UPDATEPWD, METHOD.POST, params)
}

export async function register(params) {
  return request(REGISTER, METHOD.POST, params)
}

export async function getUserList(params) {
  return request(GETUSERLIST, METHOD.POST, params)
}

export async function roleUpdate(params) {
  return request(ROLEUPDATE, METHOD.POST, params)
}

export async function userRole(params) {
  return request(USERROLE, METHOD.POST, params)
}

export async function userManage(params) {
  return request(USERMANAGE, METHOD.POST, params)
}
/**
 * 退出登录
 */
export function logout() {
  localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY)
  localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY)
  localStorage.removeItem(process.env.VUE_APP_ROLES_KEY)
  removeAuthorization()
}
export default {
  login,
  logout,
  getPhoneCode,
  getRoutesConfig,
  roleUpdate,
  getUserList,
  userRole,
  userManage
}
